package Demo2_16;

import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User：Lenovo
 * Date:2025-02-16
 * Time:14:57
 */
class MyQueue {
    private Stack<Integer> s1;
    private Stack<Integer> s2;
    public MyQueue() {
        s1=new Stack<>();
        s2=new Stack<>();
    }

    public void push(int x) {
        s1.push(x);
    }

    public int pop() {
        if(empty()){
            return -1;
        }
        if(s2.isEmpty()){
            while(!s1.isEmpty()){
                s2.push(s1.pop());
            }
        }
        return s2.pop();
    }

    public int peek() {
        if(empty()){
            return -1;
        }
        if(s2.isEmpty()){
            while(!s1.isEmpty()){
                s2.push(s1.pop());
            }
        }
        return s2.peek();
    }

    public boolean empty() {
        return s1.isEmpty()&&s2.isEmpty();
    }

    public static void main(String[] args) {
        MyQueue obj = new MyQueue();
        // 向队列中添加元素
        obj.push(1);
        obj.push(2);
        obj.push(3);

        // 获取队列头部元素
        int param_3 = obj.peek();
        System.out.println("队列头部元素: " + param_3);

        // 移除队列头部元素
        int param_2 = obj.pop();
        System.out.println("移除的队列头部元素: " + param_2);

        // 再次获取队列头部元素
        param_3 = obj.peek();
        System.out.println("移除一个元素后队列头部元素: " + param_3);

        // 检查队列是否为空
        boolean param_4 = obj.empty();
        System.out.println("队列是否为空: " + param_4);
    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.peek();
 * boolean param_4 = obj.empty();
 */